<?php 
session_start();
include("config.php");
include('checkLoggedIn.php');
$page = "edit-info";
//echo $_SESSION['userdata']['user_id'];

$data = Users::getInfo($_SESSION['userdata']['user_id']);

$first = $data['first_name'];
$last = $data['last_name'];
$phone = $data['mobile'];

if(isset($_POST['save'])){
	//if($_POST['phone'] != "" and $_POST['first'] != "" and $_POST['last'] != ""){
			// save the new values
			if(Users::updatePersonalInfo($_POST['first'], $_POST['last'],$_POST['phone']) === TRUE) {
				$_SESSION['userdata']['updated'] = "true";
				header("location:account.php");
			}else{
				$err = "There was an error processing your request at the moment. Please try again later";
				}
			/*
		} else {
			$err="Please fill in misssing fields";
		}
	*/ 
	
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<meta name="viewport" content="width=320, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Edit Personal Info</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="body-wrapper">
<div id="header"><?php include('menu.php');?></div>
<div id="Content">

		<form action="#" method="post">
		<fieldset title="Edit your information">
			<legend>Edit Personal Information</legend>
			<?php if(isset($err)):?>
			<div class="error-msg"><?php echo $err ?></div>
			<?php endif;?>
			<div class="row" style="margin-top:10px;">
			<label for="first-name">First Name</label><br/>
				<input type="text" size="30" name="first" value="<?php echo @$first;?>"></input>
			</div>
			<div class="row" style="margin-top:10px;">
			<label for="last-name">Last Name</label><br/>
				<input type="text" size="30" name ="last" value="<?php echo @$last;?>"></input>
			</div>
			<div class="row" style="margin-top:10px;">
			<label for="mobile">Mobile (eg:512-245-4043)</label><br/>
				<input type="text" size="30" name ="phone" value="<?php echo @$phone;?>"></input>
			</div>
		</fieldset>
			<div class="row">
				<input type="submit" value="Save" name="save"></input>
			</div>
		</form>
		<div class="clear"></div>
	</div>
</div>
</body>
</html>